package cn.itcast.flink.base;

import org.apache.flink.api.common.RuntimeExecutionMode;
import org.apache.flink.core.fs.FileSystem;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * Author itcast
 * Date 2021/7/27 16:22
 * 将本地数据保存到文件系统中
 */
public class WriteFileSink {
    public static void main(String[] args) throws Exception {
        //1.env
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setRuntimeMode(RuntimeExecutionMode.AUTOMATIC);
        //env.setParallelism(1);
        //2.source 生成元素或者从 words.txt 文件中读取数据
        DataStreamSource<String> source = env.readTextFile("data/test.txt");
        //3.transformation，暂时不需要
        //4.sink
        source.writeAsText("data/output/result.txt", FileSystem.WriteMode.OVERWRITE).setParallelism(1);
        //注意:
        //Parallelism=1为文件
        //Parallelism>1为文件夹
        //5.execute
        env.execute();
    }
}
